<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Size Formatter</title>
    </head>
    <script type="text/javascript" src="js/jquery-1.4.2.min.js">
    </script>;
    <script type="text/javascript">
        function sizeFormatter(bt){
			var fmtMsg = null
            var kb = byteCrunch(bt, 1);
            var mb = byteCrunch(bt, 2);
			var gb = byteCrunch(bt, 3);
            if (bt <= 1048576) {
                $('#rslts').html(kb+' KB');
            }
            else 
                if (kb <= 1048576) {
                    $('#rslts').html(mb+' MB');
                }
                else {
                    $('#rslts').html(gb+'GB');
                }
        }
		function byteCrunch(bVal, itr){
			if(itr == 0){
				return Math.round(bVal);
			}
			return byteCrunch(Math.round(bVal / 1024 * 100000) / 100000, --itr);
		}
    </script>
    <body>
        <table border="1" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <input type="text" id="kbInpt">
                </td>
                <td>
                    <input type="button" value="format" onclick="sizeFormatter($('#kbInpt').val())">
                </td>
            </tr>
            <tr>
                <td>
                    Results
                </td>
                <td id="rslts">
                </td>
            </tr>
        </table>
    </body>
</html>
